<?php

namespace app\api\controller;

use app\model\Activity as A;

class Activity extends ApiBase
{
 

   
    //list 分页
    public function list()
    {
        $list = (new A())->where("status","=",1)->order('sort','desc')->paginate(input('limit/d'));
        $list = $list->toArray();
        $data = [];
        foreach ($list['data'] as  &$v) {
            $data[] = [
                'id' => $v['id'],
                'title' => $v['title'],
                'img' => $v['img'],
                'img_vertical' => $v['img_vertical'],
                'start_time' => date('Y-m-d',$v['start_time']),
                'end_time' => date('Y-m-d',$v['end_time']),
                'desc' => $v['desc'],
                'address' => $v['address'],
                'tag' => $v['tag'],
            ];
        }
        $res = [
            'data' => $data,
            'page' => $list['current_page'],
            'total' => $list['total'],
        ];
        return $this->returnApi($res,code: 0);
    }

    //detail 详情
    public function detail()
    {
        $id = input('id',0);
        if (empty($id)) {
            return $this->returnApi([],1,'id不能为空');
        }
        $where = [];
        $where[] = ['id','=', $id];
        $where[] = ['status','=',1];
        $detail = (new A())->where("id","=", $id)->find();
        if (empty($detail)) {
            return $this->returnApi([],1,"活动不存在");
        }
        $detail['start_time'] = date('Y-m-d',$detail['start_time']);
        $detail['end_time'] = date('Y-m-d',$detail['end_time']);
        $detail['img'] = $detail['img'];
        $detail['img_vertical'] = $detail['img_vertical'];
        $detail['desc'] = $detail['desc'];
        $detail['address'] = $detail['address'];
        $detail['tag'] = $detail['tag'];
        $detail['content'] =  $detail['content'];
        return $this->returnApi($detail,0,'成功');
    
    }
}